git bisect 사용하여 버그 시작지점 검색하기
git bisect
is a binary search tool built into Git that helps you quickly identify the commit that introduced a bug or regression. Instead of manually checking each commit, Git automates the search by checking commits halfway between a known good and bad commit.
🔧 Basic Workflow
-
Start bisect:
git bisect start
-
Mark the current (bad) commit:
git bisect bad
-
Mark a known good commit (where the bug didn't exist):
git bisect good <good_commit_hash>
-
Git will now checkout a commit halfway between good and bad. You test it manually:
-
If the bug is present:
git bisect bad
-
If the bug is not present:
git bisect good
-
-
Repeat step 4 until Git finds the exact commit that introduced the issue.
-
End bisecting session:
git bisect reset
🧪 Example
git bisect start
git bisect bad # current commit has a bug
git bisect good abc1234 # abc1234 is a known good commit
# Test commit checked out by Git
git bisect bad # if buggy
# Repeat until Git outputs:
# <bad_commit_hash> is the first bad commit
git bisect reset # go back to original HEAD
🛠️ Bonus: Automate Testing
If you have a test script (exit code 0 = good, non-zero = bad):
git bisect run ./test-script.sh
🎯 Use Cases
-
Find when a bug was introduced
-
Detect when a performance regression happened
-
Discover breaking API changes in a library
Would you like an example use case applied to a real-world project?